---
title: "Statistical Analysis of Our Data - Fixed Onion Prices"
author: "Digvijay Ghotane"
date: "5/20/2020"
output: pdf_document
header-includes:
  - \usepackage{dcolumn}
  - \usepackage{rotating, graphicx}
  - \maxdeadcycles=200
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, results = 'hide')
```
```{r message = F, warning=F}
require(tidyverse)
require(stargazer)
require(lubridate)
require(zoo)
library(mfx)
require(psych)
library(skimr)
```

```{r message = F}
final = read_csv('data/output_data/final_onion_fixed.csv')
```
  
```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final, family = binomial(link="logit"))
ivset2 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final, family = binomial(link="logit"))
ivset3 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final, family = binomial(link="logit"))
ivset4 = glm(stone ~  KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final, family = binomial(link="logit"))
```

## Table 4.1.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("IV Set 1", "IV Set 2", "IV Set 3", "IV Set 4"),
          dep.var.labels.include = F,
          title = "Table 4.1 for Newspapers-SATP-ACLED Data (Logit Model)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c("Demonetization (Dummy)",
                              "Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)",
                              "Interaction bw Temp and Ramzan"),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% group_by(district) %>% 
  mutate(total = sum(stone)) %>% filter(total > 40), family = binomial(link="logit"))
ivset2 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final%>% group_by(district) %>% 
  mutate(total = sum(stone)) %>% filter(total > 40), family = binomial(link="logit"))
ivset3 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% group_by(district) %>% 
  mutate(total = sum(stone)) %>% filter(total > 40), family = binomial(link="logit"))
ivset4 = glm(stone ~  KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final%>% group_by(district) %>% 
  mutate(total = sum(stone)) %>% filter(total > 40), family = binomial(link="logit"))
```


## Table 4.1. (B) (Without all districts)  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("IV Set 1", "IV Set 2", "IV Set 3", "IV Set 4"),
          dep.var.labels.include = F,
          title = "Table 4.10 for Newspapers-SATP-ACLED Data (Logit Model)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c("Demonetization (Dummy)",
                              "Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)",
                              "Interaction bw Temp and Ramzan"),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(MajorityReligion == 'Muslim'), family = binomial(link="logit"))
ivset2 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(MajorityReligion != 'Muslim'), family = binomial(link="logit"))
ivset3 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(MajorityReligion == 'Muslim'), family = binomial(link="logit"))
ivset4 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(MajorityReligion != 'Muslim'), family = binomial(link="logit"))
```

## Table 4.2.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Muslim", "Non-Muslim", "Muslim", "Non-Muslim"),
          dep.var.labels.include = F,
          title = "Table 4.2 for Newspapers-SATP-ACLED Data (Logit Model) (By Majority Religion)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c("Demonetization (Dummy)",
                              #"Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)",
                              "Interaction bw Temp and Ramzan"),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(MajorityReligion == 'Muslim'), family = binomial(link="logit"))
ivset2 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(MajorityReligion != 'Muslim'), family = binomial(link="logit"))
ivset3 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(MajorityReligion == 'Muslim'), family = binomial(link="logit"))
ivset4 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(MajorityReligion != 'Muslim'), family = binomial(link="logit"))
```

## Table 4.3.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Muslim", "Non-Muslim", "Muslim", "Non-Muslim"),
          dep.var.labels.include = F,
          title = "Table 4.3 for Newspapers-SATP-ACLED Data (Logit Model) (By Majority Religion)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c(#"Demonetization (Dummy)",
                              "Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)",
                              "Interaction bw Temp and Ramzan"),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% filter(UrbanVSRural != 'R'), family = binomial(link="logit"))
ivset2 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(UrbanVSRural == 'R'), family = binomial(link="logit"))
ivset3 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(UrbanVSRural != 'R'), family = binomial(link="logit"))
ivset4 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(UrbanVSRural == 'R'), family = binomial(link="logit"))
```

## Table 4.4.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Urban", "Rural", "Urban", "Rural"),
          dep.var.labels.include = F,
          title = "Table 4.4 for Newspapers-SATP-ACLED Data (Logit Model) (By Urban versus Rural)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c("Demonetization (Dummy)",
                              #"Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)",
                              "Interaction bw Temp and Ramzan"),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(UrbanVSRural != 'R'), family = binomial(link="logit"))
ivset2 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(UrbanVSRural == 'R'), family = binomial(link="logit"))
ivset3 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(UrbanVSRural != 'R'), family = binomial(link="logit"))
ivset4 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(UrbanVSRural == 'R'), family = binomial(link="logit"))
```

## Table 4.5.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Urban", "Rural", "Urban", "Rural"),
          dep.var.labels.include = F,
          title = "Table 4.5 for Newspapers-SATP-ACLED Data (Logit Model) (By Urban versus Rural)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c(#"Demonetization (Dummy)",
                              "Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)",
                              "Interaction bw Temp and Ramzan"),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% filter(PopulationGroup != 3), family = binomial(link="logit"))
ivset2 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(PopulationGroup == 3), family = binomial(link="logit"))
ivset3 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(PopulationGroup != 3), family = binomial(link="logit"))
ivset4 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(PopulationGroup == 3), family = binomial(link="logit"))
```

## Table 4.6.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Low-Medium", "High", "Low-Medium", "High"),
          dep.var.labels.include = F,
          title = "Table 4.6 for Newspapers-SATP-ACLED Data (Logit Model) (By Population Density)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c("Demonetization (Dummy)",
                              #"Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)",
                              "Interaction bw Temp and Ramzan"),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(PopulationGroup != 3), family = binomial(link="logit"))
ivset2 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(PopulationGroup == 3), family = binomial(link="logit"))
ivset3 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(PopulationGroup != 3), family = binomial(link="logit"))
ivset4 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final%>% filter(PopulationGroup == 3), family = binomial(link="logit"))
```

## Table 4.7.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Low-Medium", "High", "Low-Medium", "High"),
          dep.var.labels.include = F,
          title = "Table 4.7 for Newspapers-SATP-ACLED Data (Logit Model) (By Population Density)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c(#"Demonetization (Dummy)",
                              "Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)",
                              "Interaction bw Temp and Ramzan"),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% filter(PopulationGroup == 1), family = binomial(link="logit"))
ivset2 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(PopulationGroup == 2), family = binomial(link="logit"))
ivset3 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(PopulationGroup == 1), family = binomial(link="logit"))
ivset4 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(PopulationGroup == 2), family = binomial(link="logit"))
```

## Table 4.8.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Low", "Medium", "Low", "Medium"),
          dep.var.labels.include = F,
          title = "Table 4.8 for Newspapers-SATP-ACLED Data (Logit Model) (By Population Density, only Low and Medium)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c("Demonetization (Dummy)",
                              #"Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)",
                              "Interaction bw Temp and Ramzan"),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(PopulationGroup == 1), family = binomial(link="logit"))
ivset2 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(PopulationGroup == 2), family = binomial(link="logit"))
ivset3 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final %>% filter(PopulationGroup == 1), family = binomial(link="logit"))
ivset4 = glm(stone ~ KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(TemperatureInC*RamzanDummy1IsRamzan) + factor(district), data = final%>% filter(PopulationGroup == 2), family = binomial(link="logit"))
```

## Table 4.9.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Low", "Medium", "Low", "Medium"),
          dep.var.labels.include = F,
          title = "Table 4.9 for Newspapers-SATP-ACLED Data (Logit Model) (By Population Density, only Low and Medium)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c(#"Demonetization (Dummy)",
                              "Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)",
                              "Interaction bw Temp and Ramzan"),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r}
final %>% group_by(district) %>% 
  mutate(total = sum(stone)) %>% filter(total > 40)
```

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~  AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(Demonetization == 0), family = binomial(link="logit"))
ivset2 = glm(stone ~  AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(Demonetization == 1), family = binomial(link="logit"))
ivset3 = glm(stone ~  AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% group_by(district) %>% 
  mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(Demonetization == 0), family = binomial(link="logit"))
ivset4 = glm(stone ~  AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% group_by(district) %>% 
  mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(Demonetization == 1) , family = binomial(link="logit"))
```

## Table 4.10.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Before-All", "After-All", "Before$>$40", "After$>$40"),
          dep.var.labels.include = F,
          title = "Table 4.10 for Newspapers-SATP-ACLED Data (Logit Model) Before and After (Demon)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c(#"Demonetization (Dummy)",
                              #"Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)"
                              #"Interaction bw Temp and Ramzan"
                              ),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(KillingBW == 0), family = binomial(link="logit"))
ivset2 = glm(stone ~ AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(KillingBW == 1), family = binomial(link="logit"))
ivset3 = glm(stone ~ AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% group_by(district) %>% mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(KillingBW == 0), family = binomial(link="logit"))
ivset4 = glm(stone ~  AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% group_by(district) %>% mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(KillingBW == 1), family = binomial(link="logit"))
```

## Table 4.11.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Before-All", "After-All", "Before$>$40", "After$>$40"),
          dep.var.labels.include = F,
          title = "Table 4.11. for Newspapers-SATP-ACLED Data (Logit Model) Before and After (KBW)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c(#"Demonetization (Dummy)",
                              #"Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)"
                              #"Interaction bw Temp and Ramzan"
                              ),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~  KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(Demonetization == 0), family = binomial(link="logit"))
ivset2 = glm(stone ~  KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(Demonetization == 1), family = binomial(link="logit"))
ivset3 = glm(stone ~  KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% group_by(district) %>% 
  mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(Demonetization == 0), family = binomial(link="logit"))
ivset4 = glm(stone ~  KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% group_by(district) %>% 
  mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(Demonetization == 1) , family = binomial(link="logit"))
```

## Table 4.12.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Before-All", "After-All", "Before$>$40", "After$>$40"),
          dep.var.labels.include = F,
          title = "Table 4.12 for Newspapers-SATP-ACLED Data (Logit Model) Before and After (Demon)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c(#"Demonetization (Dummy)",
                              "Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)"
                              #"Interaction bw Temp and Ramzan"
                              ),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~  KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + I(RamzanDummy1IsRamzan*TemperatureInC)+ factor(district), data = final %>% filter(Demonetization == 0), family = binomial(link="logit"))
ivset2 = glm(stone ~  KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price+ I(RamzanDummy1IsRamzan*TemperatureInC) + factor(district), data = final %>% filter(Demonetization == 1), family = binomial(link="logit"))
ivset3 = glm(stone ~  KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price+ I(RamzanDummy1IsRamzan*TemperatureInC) + factor(district), data = final %>% group_by(district) %>% 
  mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(Demonetization == 0), family = binomial(link="logit"))
ivset4 = glm(stone ~  KillingBW + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price+ I(RamzanDummy1IsRamzan*TemperatureInC) + factor(district), data = final %>% group_by(district) %>% 
  mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(Demonetization == 1) , family = binomial(link="logit"))
```

## Table 4.13.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Before-All", "After-All", "Before$>$40", "After$>$40"),
          dep.var.labels.include = F,
          title = "Table 4.13 for Newspapers-SATP-ACLED Data (Logit Model) Before and After (Demon)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c(#"Demonetization (Dummy)",
                              "Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)",
                              "Interaction bw Temp and Ramzan"
                              ),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(KillingBW == 0), family = binomial(link="logit"))
ivset2 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(KillingBW == 1), family = binomial(link="logit"))
ivset3 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% group_by(district) %>% mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(KillingBW == 0), family = binomial(link="logit"))
ivset4 = glm(stone ~  Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% group_by(district) %>% mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(KillingBW == 1), family = binomial(link="logit"))
```

## Table 4.11.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Before-All", "After-All", "Before$>$40", "After$>$40"),
          dep.var.labels.include = F,
          title = "Table 4.11. for Newspapers-SATP-ACLED Data (Logit Model) Before and After (KBW)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c("Demonetization (Dummy)",
                              #"Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)"
                              #"Interaction bw Temp and Ramzan"
                              ),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

\newpage

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(KillingBW == 0), family = binomial(link="logit"))
ivset2 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(KillingBW == 1), family = binomial(link="logit"))
ivset3 = glm(stone ~ Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% group_by(district) %>% mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(KillingBW == 0), family = binomial(link="logit"))
ivset4 = glm(stone ~  Demonetization + AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% group_by(district) %>% mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(KillingBW == 1), family = binomial(link="logit"))
```

## Table 4.11.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='latex', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Before-All", "After-All", "Before$>$40", "After$>$40"),
          dep.var.labels.include = F,
          title = "Table 4.11. for Newspapers-SATP-ACLED Data (Logit Model) Before and After (KBW)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c("Demonetization (Dummy)",
                              #"Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)"
                              #"Interaction bw Temp and Ramzan"
                              ),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```


```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(KillingBW == 0), family = binomial(link="logit"))
ivset2 = glm(stone ~ AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(KillingBW == 1 & Demonetization == 0), family = binomial(link="logit"))
ivset3 = glm(stone ~ AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(Demonetization == 1 & date <= as.Date("2017-04-01")), family = binomial(link="logit"))
ivset4 = glm(stone ~  AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% filter(date > as.Date("2017-04-01")), family = binomial(link="logit"))
```

## Table 4.12.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='text', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Before Killing", "After KBW, Before DM", "After DM until April", "Post April"),
          dep.var.labels.include = F,
          title = "Table 4.11. for Newspapers-SATP-ACLED Data (Logit Model)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c(#"Demonetization (Dummy)",
                              #"Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)"
                              #"Interaction bw Temp and Ramzan"
                              ),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```

```{r  warning = F, error = F, message=F}
ivset1 = glm(stone ~ AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final %>% group_by(district) %>% mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(KillingBW == 0), family = binomial(link="logit"))
ivset2 = glm(stone ~ AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% group_by(district) %>% mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(KillingBW == 1 & Demonetization == 0), family = binomial(link="logit"))
ivset3 = glm(stone ~ AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% group_by(district) %>% mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(Demonetization == 1 & date <= as.Date("2017-04-01")), family = binomial(link="logit"))
ivset4 = glm(stone ~  AmountOfPrecipitationInMM + TemperatureInC + RamzanDummy1IsRamzan + Friday + onion_price + factor(district), data = final%>% group_by(district) %>% mutate(total = sum(stone)) %>% filter(total > 40) %>% filter(date > as.Date("2017-04-01")), family = binomial(link="logit"))
```

## Table 4.12.  
```{r echo=FALSE, results='asis', warning = F, error = F, message=F}
stargazer(ivset1, ivset2, ivset3, ivset4,
          type ='text', float = T, header= F, align = T, digits = 2,
          omit = "factor", keep.stat = c("n"), notes.align = "l",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001),
          column.labels = c("Before Killing", "After KBW, Before DM", "After DM until April", "Post April"),
          dep.var.labels.include = F,
          title = "Table 4.11. for Newspapers-SATP-ACLED Data (Logit Model)",
          dep.var.caption = c("Dependent Variable is dichotomous indicating a Stone Pelting Incident Day"),
          covariate.labels = c(#"Demonetization (Dummy)",
                              #"Killing of Burhan Wani (Dummy)",
                              "Precipitation (in mm.)",
                              "Temperature (in C)",
                              "Ramzan (Dummy)",
                              "Friday (Dummy)",
                              "Onion Prices (in INR, baseline: 2012)"
                              #"Interaction bw Temp and Ramzan"
                              ),
          notes = c('Demonetization Policy effect taken into account on 10 November 2016.', 
                    'Killing of Burhan Wani effect taken into account on July 10, 2016.',
          'Controlled for unit based Fixed Effects by accounting for district dummies.'))
```


```{r}
final %>% dplyr::select(TemperatureInC, AmountOfPrecipitationInMM) %>% cor(use = "pairwise.complete.obs")
```

```{r}
final %>% group_by(district) %>% summarize(ok = n())
```

```{r}
final %>% filter(district == 'Jammu')
```

